<?php

$connect = null;

function connectSQL(){
	global $connect, $db;
	$connect = mysql_connect($db['hostname'],$db['username'],$db['password']) or die ("Error: could not connect to database");
	mysql_select_db($db['dbname']);
}

function disconnectSQL(){
	global $connect;
	mysql_close($connect);
}


function runSQL($rsql, $params=false) {
	global $connect;
	$safe_sql = mysql_safe($rsql, $params);
	$result = mysql_query($safe_sql) or die ('Error (' . mysql_errno($connect) . ') ' . mysql_error($connect) . ' at ' . $safe_sql ); 
	return $result;
}

function mysql_safe($query,$params=false) { 
    if ($params) { 
        foreach ($params as &$v) { $v = mysql_real_escape_string($v); }    # Escaping parameters 
        $query = vsprintf( $query , $params );
        //echo $query;   
    } 
    return ($query); 
} 

?>